<?php
if (!defined('_THRIFT_CLIENT')) {
	include "ThriftClient.php";
}

include $GLOBALS['THRIFT_ROOT'] . '/packages/miniblog/miniblog.php';

class MiniblogService extends ThriftClient {

    public function __construct($server = '10.1.254.42', $port = '9097'){
        if ( ! isset($server) OR ! isset($port))
            return false;

        try {
            $this->_socket = new TSocket($server, $port);
            $this->_transport = new TBufferedTransport($this->_socket, 1024, 1024);
            $this->_protocol = new TBinaryProtocol($this->_transport);
            $this->_client_instance = new miniblogClient($this->_protocol);
        } catch (TException $tx){
            var_dump($tx);
            return false;
        }

        return true;
    }
    
    public function follow($follower, $following)
    {
        $this->OpenTransport();
        $res = $this->_client_instance->follow($follower, $following);
        $this->CloseTransport();
        return $res;    
    }
    
    public function deleteFollow($follower, $following)
    {
        $this->OpenTransport();
        $res = $this->_client_instance->deleteFollow($follower, $following);
        $this->CloseTransport();        
        return $res;    
    }
    
    public function isFollowing($follower, $following)
    {
        $this->OpenTransport();
        $res = $this->_client_instance->isFollowing($follower, $following);
        $this->CloseTransport();        
        return $res;    
    }
    
    public function getFollowing($uid, $page = 1, $limit = 15)
    {
        $this->OpenTransport();
        $res = $this->_client_instance->getFollowing($uid, $page, $limit);
        $this->CloseTransport();        
        return $res;    
    }
    
    public function getFollower($uid, $page = 1, $limit = 15)
    {
        $this->OpenTransport();
        $res = $this->_client_instance->getFollower($uid, $page, $limit);
        $this->CloseTransport();        
        return $res;    
    }
}

